package cn.gok.manage.web;


import cn.gok.manage.service.CategoryService;
import cn.gok.pojo.Category;
import cn.gok.util.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.xml.transform.Result;

@Controller
@RequestMapping("/manage/category")
public class CategoryController {

    @Autowired
    CategoryService categoryService;


    @ResponseBody
    @RequestMapping("/get_category.do")
    public ResultData getCategoryById(Integer parentId){
        return categoryService.getCategoryById(parentId);
    }

    @ResponseBody
    @RequestMapping("/add_category.do")
    public ResultData insertCategoryParentIdAndName(@RequestParam(defaultValue = "0")Integer parentId,
                                                    String name){
        return categoryService.insertCategoryParentIdAndName(parentId,name);
    }

    @ResponseBody
    @RequestMapping("/set_category_name.do")
    public ResultData updateNameById(Integer id,String name){
        return categoryService.updateNameById(id,name);
    }

    @ResponseBody
    @RequestMapping("/get_deep_category.do")
    public ResultData getDeepCategory(int categoryId){
        return categoryService.getDeepCategory(categoryId);
    }
}
